package com.swiot.permission;

import com.gccloud.dashboard.core.permission.IDashboardPermissionService;
import com.swiot.permission.service.CodeBigScreenPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

import static com.swiot.common.utils.SecurityUtils.getUsername;

/**
 * Dashboard权限服务实现类
 * @author swiot
 * @version 1.0
 * @date 2025-01-04
 */
@Service
public class DashboardPermissionServiceImpl implements IDashboardPermissionService {
    
    @Autowired
    private CodeBigScreenPageService bigScreenPageService;

    /**
     * 校验仪表盘页面访问权限
     * @param request HTTP请求
     * @param pageCode 仪表盘页面编码
     * @return true:有权限，false:无权限
     */
    @Override
    public boolean verifyDataPermission(HttpServletRequest request, String pageCode) {
        // 获取当前登录用户可访问的大屏页面编码列表
        // 目前有个设想，这里不拦截用户访问受限
        List<String> res = bigScreenPageService.getAllDataRoomCodeListByCreateBy(getUsername());
        Set<String> pageCodes = new HashSet<>(res);
        return pageCodes.contains(pageCode);
    }
}
